{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<html>\n",
      "<head><title>403 Forbidden</title></head>\n",
      "<body>\n",
      "<center><h1>403 Forbidden</h1></center>\n",
      "</body>\n",
      "</html>\n",
      "\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "headers = {'Cookie': 'JSESSIONID=FCE1831DE4B31EB24692889FC6ED336A; _ga=GA1.1.661790863.1727231453; _ga_S17ZS9ZPHD=GS1.1.1727231453.1.1.1727231500.0.0.0'}\n",
    "resp = requests.post('https://www.arabidopsis.org/api/search/gene', headers=headers, json={\"searchText\":\"NPC\"})\n",
    "print(resp.text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "import json\n",
    "headers = {\n",
    "    \"Cookie\" : \"token=BQCVAUbY5KE6SoP04VcoVhFKtW+blJrNNq8Zn7sVqXHyW9x18W9niwJ4AMS2vwO4Isdc0tvnSV1esUMNapUNEROCOG2s9Hdb3jkhu6z7dNu2aFfFZzORU3TDtffNtU8DK3CXnNPvVXzPtowm5IzDzPJ44g8pChhHUNjuYlWT40TbvuX3PnnaTx2WPwHYS6f6N7AA6po9eBbx60eS3+8QKZbF8xglkexb5YEPUUXEjKBSbDn+MNr7A1pggX868GCzSyEfj3Ae4jmg6YUiTy/UBMW3whQoeAzwE8EwDLiSHbZsLSRu49fGUrWCTaZtsEW8nd8PtrtLESM2pqN3fMwS0MjxxDYAvr8hIK9w/hayRIeT1g41MQvOI2hzwBjHRnY01LLuKgFk6N8aX8Va7syu+RR5qSElPuYfTaAuiFoi6rpuD1gaHQp+Sxa2eIIruyXloJkBXVC6uHOZNOA8ghqtXR1ze0BZg/GthcTdvW2YEcYkZjVhYzNkMjktODg1MC00MDNmLWE3NjgtMmJhMzhhMWRmYjViAAAAACMiISAfHh0cGxoZGBcWFRQTEhEQDw4NDAsKCQgHBgUEAwIB58N/C/nZ3ywHeuTRFY/HUGFUyD7ZccZUuq0rik4fiQE=; _frid=8a21010d7fed4ed2ab3bc98785758bc8; HWWAFSESID=0fc15768f23e744065; HWWAFSESTIME=1725516636873; _fr_ssid=c4c9cf33167d4d608c748e6b80d0245c; _fr_pvid=ee074021db30405cb1b6fd317b209d82\",\n",
    "    \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3\",     \n",
    "}\n",
    "def searchCVE(url, cve):\n",
    "    data = {\"internalId\":None,\n",
    "     \"repoName\":None,\n",
    "     \"versionNum\":None,\n",
    "     \"processStage\":[],\n",
    "     \"cveId\": str(cve),\n",
    "     \"vulnSource\":None,\n",
    "     \"vulnOwner\":None,\n",
    "     \"createTime\":None,\n",
    "     \"expirationDate\":None,\"startExpirationDate\":None,\"endExpirationDate\":None,\"startCreateTime\":None,\"endCreateTime\":None,\"sortField\":\"\",\n",
    "     \"sortType\":\"DESC\",\"pageSize\":10,\n",
    "     \"currentPage\":1,\"totalSize\":1,\"type\":1}\n",
    "    response = requests.post(url, headers=headers, json=data)\n",
    "    return response.text\n",
    "vulnerabilityType = {1: '非漏洞', 2: '重复漏洞', 3: '漏洞详情缺失', 4: '误报', 5: '漏洞已修改', 6: '其他'}\n",
    "def getVulnerabilityType(json):\n",
    "    if len(json['data']['dataList']) == 0:\n",
    "        return None\n",
    "    return vulnerabilityType[json['data']['dataList'][0]['vulnerabilityType']]\n",
    "def getInternalId(json):\n",
    "    if len(json['data']['dataList']) == 0:\n",
    "        return None\n",
    "    return json['data']['dataList'][0]['internalId']\n",
    "def getType(cve):\n",
    "    resp = searchCVE('https://ci.openharmony.cn/api/opensoftware/vulnerability/analyze/1', cve=cve)\n",
    "    j = json.loads(resp)\n",
    "    return getVulnerabilityType(j)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "有效漏洞\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "import json\n",
    "headers = {\n",
    "    \"Cookie\" : \"token=BQCVAUbY5KE6SoP04VcoVhFKtW+blJrNNq8Zn7sVqXHyW9x18W9niwJ4AMS2vwO4Isdc0tvnSV1esUMNapUNEROCOG2s9Hdb3jkhu6z7dNu2aFfFZzORU3TDtffNtU8DK3CXnNPvVXzPtowm5IzDzPJ44g8pChhHUNjuYlWT40TbvuX3PnnaTx2WPwHYS6f6N7AA6po9eBbx60eS3+8QKZbF8xglkexb5YEPUUXEjKBSbDn+MNr7A1pggX868GCzSyEfj3Ae4jmg6YUiTy/UBMW3whQoeAzwE8EwDLiSHbZsLSRu49fGUrWCTaZtsEW8nd8PtrtLESM2pqN3fMwS0MjxxDYAvr8hIK9w/hayRIeT1g41MQvOI2hzwBjHRnY01LLuKgFk6N8aX8Va7syu+RR5qSElPuYfTaAuiFoi6rpuD1gaHQp+Sxa2eIIruyXloJkBXVC6uHOZNOA8ghqtXR1ze0BZg/GthcTdvW2YEcYkZjVhYzNkMjktODg1MC00MDNmLWE3NjgtMmJhMzhhMWRmYjViAAAAACMiISAfHh0cGxoZGBcWFRQTEhEQDw4NDAsKCQgHBgUEAwIB58N/C/nZ3ywHeuTRFY/HUGFUyD7ZccZUuq0rik4fiQE=; _frid=8a21010d7fed4ed2ab3bc98785758bc8; HWWAFSESID=0fc15768f23e744065; HWWAFSESTIME=1725516636873; _fr_ssid=c4c9cf33167d4d608c748e6b80d0245c; _fr_pvid=ee074021db30405cb1b6fd317b209d82\",\n",
    "    \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3\",     \n",
    "}\n",
    "def searchCVE(url, cve):\n",
    "    data = {\"internalId\":None,\n",
    "     \"repoName\":None,\n",
    "     \"versionNum\":None,\n",
    "     \"processStage\":[],\n",
    "     \"cveId\": str(cve),\n",
    "     \"vulnSource\":None,\n",
    "     \"vulnOwner\":None,\n",
    "     \"createTime\":None,\n",
    "     \"expirationDate\":None,\"startExpirationDate\":None,\"endExpirationDate\":None,\"startCreateTime\":None,\"endCreateTime\":None,\"sortField\":\"\",\n",
    "     \"sortType\":\"DESC\",\"pageSize\":10,\n",
    "     \"currentPage\":1,\"totalSize\":1,\"type\":1}\n",
    "    response = requests.post(url, headers=headers, json=data)\n",
    "    return response.text\n",
    "vulnerabilityType = {0:'有效漏洞', 1: '非漏洞', 2: '重复漏洞', 3: '漏洞详情缺失', 4: '误报', 5: '漏洞已修改', 6: '其他'}\n",
    "def getVulnerabilityType(json):\n",
    "    if len(json['data']['dataList']) == 0:\n",
    "        return None\n",
    "    return vulnerabilityType[json['data']['dataList'][0]['vulnerabilityType']]\n",
    "def getInternalId(json):\n",
    "    if len(json['data']['dataList']) == 0:\n",
    "        return None\n",
    "    return json['data']['dataList'][0]['internalId']\n",
    "def getType(cve):\n",
    "    resp = searchCVE('https://ci.openharmony.cn/api/opensoftware/vulnerability/analyze/1', cve=cve)\n",
    "    j = json.loads(resp)\n",
    "    return getVulnerabilityType(j)\n",
    "print(getType('CVE-2024-36286'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "漏洞已修改\n"
     ]
    }
   ],
   "source": [
    "print(getType('CVE-2021-47401'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "OHPSIRT-2024-058567\n"
     ]
    }
   ],
   "source": [
    "resp = searchCVE('https://ci.openharmony.cn/api/opensoftware/vulnerability/analyze/1', 'CVE-2023-52699')\n",
    "import json\n",
    "json.loads(resp)\n",
    "def getInternalId(json):\n",
    "    if len(json['data']['dataList']) == 0:\n",
    "        return None\n",
    "    return json['data']['dataList'][0]['internalId']\n",
    "internalId = getInternalId(json.loads(resp))\n",
    "print(internalId)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CONFIG_SYSV_FS未开启 不涉及\n"
     ]
    }
   ],
   "source": [
    "resp = requests.get(\"https://ci.openharmony.cn/api/opensoftware/vulnerability/analyze/OHPSIRT-2024-058567\", headers=headers).text\n",
    "dict = json.loads(resp)\n",
    "\n",
    "def getInternalId(json):\n",
    "    if len(json['data']['dataList']) == 0:\n",
    "        return None\n",
    "    return json['data']['dataList'][0]['internalId']\n",
    "def getAnalyzeReason(internalId):\n",
    "    resp = requests.get('https://ci.openharmony.cn/api/opensoftware/vulnerability/analyze/'+internalId, headers=headers).text\n",
    "    dict = json.loads(resp)\n",
    "    if len(dict['data']['details']) == 0:\n",
    "        return None\n",
    "    return dict['data']['details'][0]['analyzeReason']\n",
    "print(getAnalyzeReason('OHPSIRT-2024-058567'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'误报'"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vulnerabilityType = {1: '非漏洞', 2: '重复漏洞', 3: '漏洞详情缺失', 4: '误报', 5: '漏洞已修改', 6: '其他'}\n",
    "def getVulnerabilityType(json):\n",
    "    if len(json['data']['dataList']) == 0:\n",
    "        return None\n",
    "    return vulnerabilityType[json['data']['dataList'][0]['vulnerabilityType']]\n",
    "getVulnerabilityType(json.loads(resp))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
